<template>
  <div>
    <div class="job-page resume-page">
      <div class="job-page-center">
        <div class="job-content">
          <div class="job-content-left">
            <!-- 基本信息的组件 -->
            <div class="job-box resume-head-name">
              <basic-information
                :form="form"
                v-if="form.sta !=0"
                :info="data.resumeTalentInfo"
                @on-pitch="initData"
              ></basic-information>
              <edit-information
                v-if="form.sta == 0"
                :form="form"
                :jobSta="jobSta"
                :cityType="cityType"
                :resumeTalentInfo="resumeTalentInfo"
                @on-pitch="initData"
              ></edit-information>
            </div>
            <!-- 基本信息的组件 -->
            <div class="job-box resume-head-content">
              <!-- 期望职位的组件 -->
              <expectation-job
                :form="form"
                :enterpriseType="enterpriseType"
                :practiceType="practiceType"
                :data="data.resumeJobIntention||[]"
                @on-pitch="initData"
              ></expectation-job>
              <!-- 期望职位的组件 -->
              <!-- 工作经历的组件 -->
              <work-experience
                :form="form"
                :enterpriseType="enterpriseType"
                :practiceType="practiceType"
                :cityType="cityType"
                :data="data.resumeWorkExpList||[]"
                @on-pitch="initData"
              ></work-experience>
              <!-- 工作经历的组件 -->
              <!-- 项目经历 -->
              <project-experience
                :form="form"
                @on-pitch="initData"
                :data="data.resumeProjectExpList||[]"
              ></project-experience>
              <!-- 项目经历 -->
              <!-- 执业证书 -->
              <practice-certificate
                :data="data.talentLicenseList||[]"
                :form="form"
                :practiceType="practiceType"
                @on-pitch="initData"
              ></practice-certificate>
              <!-- 执业证书 -->
              <!-- 教育经历 -->
              <education-experience
                :data="data.resumeEducationExpList||[]"
                :form="form"
                :educationType="educationType"
                @on-pitch="initData"
              ></education-experience>
              <!-- 教育经历 -->
              <!-- 职称 -->
              <job-title
                :technicalType="technicalType"
                @on-pitch="initData"
                :data="data.talentTitleList"
              ></job-title>
              <!-- 职称 -->
            </div>
          </div>
          <div class="job-content-right">
            <div class="job-box job-resume resume-full">
              <div class="job-resume-sub">
                <span>简历完整度</span>
                <span>{{data.resumeIntegrity.resumeIntegrity}}%</span>
              </div>
              <el-progress :percentage="data.resumeIntegrity.resumeIntegrity" :show-text="false"></el-progress>
              <el-row>
                <upload type="1" url="/talent/uploadResume.do" @on-pitch="initData">
                  <el-button class="upload">
                    <img src="../../assets/img/upload.png" style="width:20px;height:20px;">
                    {{msg}}附件简历
                  </el-button>
                  <div class="upload-sub-text">支持doc/docx/pdf/png/jpg,大小不超过8M</div>
                </upload>
              </el-row>
              <el-row>
                <a v-if="data.attachResume != ''"  target="_blank" @click="download(data.attachResume)" >
                  <el-button class="upload download">
                    <img src="../../assets/img/download.png" height="18px">下载附件简历
                  </el-button>
                </a>
              </el-row>
              <div class="job-resume-button">
                <el-button class="primary-button orange-button" @click="doPreview">简历预览</el-button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <page-footer></page-footer>
  </div>
</template>

<script>
import upload from '../../components/upload'
import basicInformation from './basic-information'
import editInformation from './edit/edit-information'
import expectationJob from './expectation-job'
import workExperience from './work-experience'
import projectExperience from './project-experience'
import practiceCertificate from './practice-certificate'
import educationExperience from './education-experience'
import jobTitle from './job-title'
import pageFooter from '../../components/page-footer'
import _subject from '../../assets/utils/subject'
export default {
  data() {
    return {
      information: true, //控制基本信息组件的现实与隐藏
      msg: '上传',
      form: {
        sta: -1, //控制某个表单的显示隐藏 -1表示所有的都隐藏
        editSta: -1 //控制某个表单的显示隐藏-1为编辑
      },
      data: {
        resumeEducationExpList: [],
        resumeJobIntention: [],
        resumeProjectExpList: [],
        resumeTalentInfo: {},
        resumeWorkExpList: [],
        talentLicenseList: [],
        talentTitleList: [],
        resumeIntegrity: {}
      }, //后台返回的所有数据
      enterpriseType: [], //企业类型
      practiceType: [], //执业类型
      cityType: [], //所在地区
      jobSta: [], //求职状态
      educationType: [], //学历
      technicalType: [], //职称
      state: 0
    }
  },
  methods: {
    download(url){
      let fname = url.split('?')[0].split('com/')[1];
      (oss.down(fname)).then(res=>{
         window.open(res,"_blank");
      })
    },
    doPreview() {
      //跳转到简历预览页面
      let routerUrl = this.$router.resolve({
        path: '/resume/preview'
      })
      window.open(routerUrl.href, '_blank')
    },
    initData() {
      //console.log("www","===============")
      //初始化页面数据
      _g.apiPost('/talent/initResumePage.do', { state: this.state }).then(
        res => {
          this.data = res.data
          this.resumeTalentInfo = res.data.resumeTalentInfo
          localStorage.setItem(
            'resumeIntegrity',
            JSON.stringify(res.data.resumeIntegrity)
          )
          console.log(this.data)
          localStorage.setItem(
            localSaved.userInfo,
            JSON.stringify(this.data.resumeTalentInfo)
          )
          _subject.event.next('image')
          if (this.data.attachResume != '') {
            this.msg = '更改'
          } else {
            this.msg = '上传'
          }
          //根据id取得对应的静态数据
          for (let i = 0; i < res.data.allStaticRecordList.length; i++) {
            if (res.data.allStaticRecordList[i].id == 10) {
              this.enterpriseType =
                res.data.allStaticRecordList[i].staticRecordList
            }
            // if (res.data.allStaticRecordList[i].id == 13) {
            //   this.practiceType = res.data.allStaticRecordList[i].staticRecordList
            // }
            if (res.data.allStaticRecordList[i].id == 15) {
              this.technicalType =
                res.data.allStaticRecordList[i].staticRecordList
            }
            if (res.data.allStaticRecordList[i].id == 14) {
              this.cityType = res.data.allStaticRecordList[i].staticRecordList
            }
            if (res.data.allStaticRecordList[i].id == 33) {
              this.jobSta = res.data.allStaticRecordList[i].staticRecordList
            }
            if (res.data.allStaticRecordList[i].id == 34) {
              this.educationType =
                res.data.allStaticRecordList[i].staticRecordList
            }
          }
        }
      )

      _g.apiPost('/login/getAllStaticRecord.do', {}).then(res => {
        this.practiceType = res.data.allLicenseList
      })
      this.state = 1
    }
    // ,
    // downResume() {
    //   window.open(this.data.attachResume, '_blank')
    // }
  },
  mounted() {
    this.state = 0
    this.initData()
  },
  components: {
    upload,
    basicInformation,
    editInformation,
    expectationJob,
    workExperience,
    projectExperience,
    practiceCertificate,
    educationExperience,
    jobTitle,
    pageFooter
  }
}
</script>

<style lang="scss" scoped>
.orange-button {
  width: 100%;
  height: 40px;
  font-size: 18px;
}
.download {
  background: #009944 !important;
  color: #fff !important;
  border: 1px solid #009944 !important;
}
.upload-sub-text {
  font-size: 11px;
  color: #f15c18;
}
</style>
